﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DCT.AutoUpdate.App
{
    /// <summary>
    /// Interaction logic for UpdatePromt.xaml
    /// </summary>
    public partial class UpdatePromt : Window
    {
        public UpdatePromt()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(UpdatePromt_Loaded);
        }

        private static void AppendNewLine(TextBlock tb, string content) {
            string ori = tb.Text;
            string newtext = ori;
            if (ori.Trim() != "") {
                newtext += Environment.NewLine;
            }
            newtext += content;
            tb.Text = newtext;
        }

        void UpdatePromt_Loaded(object sender, RoutedEventArgs e)
        {
            AppendNewLine(lblVersion, "当前版本：" + App.Cache["currentver"].ToString());
            AppendNewLine(lblVersion, "最新版本：" + App.Config.GetVal("version",""));

            int index = 1;
            foreach (var item in App.Config.GetListVal("whatsnew"))
            {
                AppendNewLine(lblWhatsnew, (index++).ToString() + "." + item.Trim());
            }
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mw = new MainWindow();
            mw.Show();
            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
